// components/seleteActicity/index.js
import { activitySimpleList } from '../../api/activity';
Component({
	/**
	 * 组件的初始数据
	 */
	data: {
		detailsShowState: false,
		activityData: [],
		xzList: []
	},
	options: {
		styleIsolation: 'shared',
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		getActivityList() {
			activitySimpleList({ stage: 1, pageSize: 200 }).then(res => {
				res.data.result.map(vv => {
					vv.isXz = this.data.xzList.find(v => { return vv.id == v.id})
				})
				this.setData({
					activityData: res.data.result
				})
			})	
		},
		closeDetails() {
			this.setData({
				detailsShowState: false
			})
		},
		openDetails(list) {
			this.setData({
				detailsShowState: true,
				xzList: list
			}, () => {
				this.getActivityList()
			})
		},
		xzItem(e) {
			let data = this.data.activityData;
			let index = e.currentTarget.dataset.index;
			data[index].isXz = !data[index].isXz
			this.setData({
				activityData: data
			})
		},
		hanleBtn() {
			let data = JSON.parse(JSON.stringify(this.data.activityData))
			let list = []
			data.map(v => {
				v.isXz && list.push(v)
			})
			if (list.length > 10) {
				wx.showToast({
					icon: 'none',
					title: '最多添加10个活动'
				})
				return false;
			}
			this.triggerEvent('xzActivityData', { activityList: list }, {})
			this.closeDetails()
		}
	}
})
